package com.design.proxy.normal_dynamic;

import java.lang.reflect.Proxy;

/**
 * @ClassName DynamicProxy.java
 * @Description	动态代理
 * @author Jon
 * @date 2018年6月14日 下午2:52:43
 */
public class DynamicProxy {
	@SuppressWarnings("unchecked")
	public static <T> T newProxyInstance(Subject subject) {
		if (true) {
			new BeforeAdvice().exec();
		}
		//获取ClassLoader
		ClassLoader classLoader = subject.getClass().getClassLoader();
		//获取接口数组
		Class<?>[] interfaces = subject.getClass().getInterfaces();
		//获取handler
		MyInvocationHandler handler = new MyInvocationHandler(subject);
		return (T) Proxy.newProxyInstance(classLoader, interfaces, handler);
	}
}
